package com.wowangz.cms.common.select;

import java.io.IOException;
import java.util.ArrayList;
import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;

/**
 * 
 * @author leiyang3
 *
 */
public class BaseSelect {
	
	private ArrayList<BaseOption> options = new ArrayList<BaseOption>();
	private ObjectMapper mapper = new ObjectMapper();
	
	public void addNone(){
		options.add(new BaseOption("-1", "&nbsp;"));
	}
	
	public void addAll(){
		options.add(new BaseOption("0", "全部"));
	}
	
	public void addAll_(){
		options.add(new BaseOption("-1", "全部"));
	}
	
	public void addAllEmpty(){
		options.add(new BaseOption("", "全部"));
	}
	
	public void addNoneEmpty(){
		options.add(new BaseOption("", "&nbsp;"));
	}
	
	public void addSelectEmpty(){
		options.add(new BaseOption("", "请选择"));
	}
	
	public void addOption(String key, String value){
		options.add(new BaseOption(key, value));
	}
	
	public void addOption(long key, String value){
		options.add(new BaseOption(String.valueOf(key), value));
	}
	
	public String getJSONSelectInfo(){
		String jsonString = "";
		try {
			jsonString = mapper.writeValueAsString(options);
		} catch (JsonGenerationException e) {
			e.printStackTrace();
		} catch (JsonMappingException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return jsonString;
	}
	
	public ArrayList<BaseOption> getOptions(){
		return options;
	}
}
